///////////////////////////////////////////////////////////
// Frame.h
//
// FrameWindow: a wxFrame used to show a wxPanel in a framed window
// Parent child - relations between windows
//	
//	           TopWindow
//	        _______|______
//	       |              |
//	       v              v
//	   AttachedWindow   FrameWindow
//	       |_______ ______|
//	               |
//	               v
//	           ViewOpenGL
//
#ifndef STAND_ALONE_WINDOW_H
#define STAND_ALONE_WINDOW_H

#include <QLabel>
#include <QMainWindow>
#include <QToolbar>
#include <QMenubar>
#include <QProgressBar>
#include <QKeyEvent>
#include <QDebug>
#include <QProxyStyle>
#include <QStyle>

#include <windows.h>

#include "MainWindow.h"

Q_DECLARE_METATYPE(QAction*)

namespace IDS{
namespace IDEAS{
namespace OpenGLView{
namespace Fwk {

class UserInteractionManager;

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
class MyProxyStyle : public QProxyStyle
{
	Q_OBJECT

public:
	// -----------------------------------------------------------------------------------------------
     int styleHint(StyleHint hint,
					const QStyleOption *option = 0,
					const QWidget *widget = 0,
					QStyleHintReturn *returnData = 0) const
     {
         if (hint == QStyle::SH_ToolButton_PopupDelay)  return 200;
		 if (hint == QStyle::SH_Menu_Scrollable)
			 return 1;
         return QProxyStyle::styleHint(hint, option, widget, returnData);
     }

	
	 // -----------------------------------------------------------------------------------------------
	 int pixelMetric(PixelMetric metric,
		const QStyleOption * option = 0,
		const QWidget * widget = 0 ) const 
	{
		int size = QProxyStyle::pixelMetric(metric, option, widget);

		switch( metric )
		{
		case QStyle::PM_SmallIconSize:	 size = 32; break;
		//case QStyle::PM_ToolBarItemMargin:				size = 4; break;
		//case QStyle::PM_ToolBarItemSpacing:				size = 4; break;
		case QStyle::PM_ToolBarIconSize: size = 32; break;
		}

		return 	size;
	}

};


////////////////////////////////////////////////////////////////////////////////////////////////////
// @brief	Stand alone windows class
//
// @author	D.vacca
// @date	24/05/2010
////////////////////////////////////////////////////////////////////////////////////////////////////
class StandAloneWindow : public QMainWindow, public MainWindow
{
	Q_OBJECT
private:
	int borders_w;
	int borders_h;
	void _init_createActions();
	void _init_createMenus();
	void _init_createToolBars();
	void _init_statusBar();

	void _deinit_destroyActions();
	void _deinit_destroyMenus();
	void _deinit_destroyToolBars();

	void closeEvent(QCloseEvent *event);
	void resizeEvent(QResizeEvent *event);
	void moveEvent(QMoveEvent *event);

	UserInteractionManager		*uim;

public:
	StandAloneWindow(ViewInterface::ViewGraphic *owner);
	virtual ~StandAloneWindow();

	void updateToolbar();

	//void postInitialization();
	void loadShortcuts();
	void setSettings(ViewInterface::GraphicsViewSettings *settings);
	void setWindowTitle(const std::string &title);
	void setStatusMessage(const std::string &status);
	void setStatusPosition(const IDSReal2D &chartPoint, const IDSReal2D &geoPoint, double elevation);
	void setStatusPercentage(double percent);
	void setWindowSize(int x, int y, int w, int h);
	void showToolbars();
	void showWindow();
	ClientSize getClientSize();
	void setCursor(unsigned int cursorID);
	
	void dockWindow(void *window, void *action, DockType dock);



	WindowType getWindowType() {return StandAloneType;}

#pragma region QTCode
// ================================================================================================
//                                              QT 
// ================================================================================================
private slots:
	void command_openFile();
	void command_saveFile();
	void command_exit();

	void fireMainAction();
	void firePointsAction();
	void fireSegmentsAction();
	void fireArcsAction();
	//void fireTangentsAction();
	//void fireWindspiralAction();
	void fireLociAction();
	void fireShapesAction();
	void fireCurveOperationsAction();
	void fireShapeOperationsAction();
	void fireMeasuresAction();

	void swapMainAction(QAction *src, bool fire = true);
	void swapPointsAction(QAction *src, bool fire = true);
	void swapSegmentsAction(QAction *src, bool fire = true);
	void swapArcsAction(QAction *src, bool fire = true);
	//void swapTangentsAction(QAction *src, bool fire = true);
	//void swapWindspiralAction(QAction *src, bool fire = true);
	void swapLociAction(QAction *src, bool fire = true);
	void swapShapesAction(QAction *src, bool fire = true);
	void swapCurveOperationsAction(QAction *src, bool fire = true);
	void swapShapeOperationsAction(QAction *src, bool fire = true);
	void swapMeasuresAction(QAction *src, bool fire = true);

	void cycleMainAction();
	void cyclePointsAction();
	void cycleSegmentsAction();
	void cycleArcsAction();
	//void cycleTangentsAction();
	//void cycleWindspiralAction();
	void cycleLociAction();
	void cycleShapesAction();
	void cycleCurveOperationsAction();
	void cycleShapeOperationsAction();
	void cycleMeasuresAction();

private:
	QAction *openAction;
	QAction *saveAction;
	QAction *exitAction;

	QAction *placeHolderMain;
	QAction *placeHolderPoints;
	QAction *placeHolderSegments;
	QAction *placeHolderArcs;
	//QAction *placeHolderTangents;
	//QAction *placeHolderWindspiral;
	QAction *placeHolderLoci;
	QAction *placeHolderShapes;
	QAction *placeHolderCurveOperations;
	QAction *placeHolderShapeOperations;
	QAction *placeHolderMeasures;

	std::vector<QAction*> mainActions;
	std::vector<QAction*> pointsActions;
	std::vector<QAction*> segmentsActions;
	std::vector<QAction*> arcsActions;
	std::vector<QAction*> lociActions;
	std::vector<QAction*> shapesActions;
	std::vector<QAction*> shapeOperationsActions;
	std::vector<QAction*> measuresActions;
	std::vector<QAction*> operationsActions;

	QAction *actCloneObj;
	QAction *actFitView;
	QAction *actZoomView;
	QAction *actDeleteObj;
	QAction *actEndCapture;

	QAction *actClipClean;
	QAction *actClipSave;
	QAction *actClipDone;

	QMenuBar *appMenu;
	QToolBar *dockableToolBar;
	QToolBar *floatingToolBar;
	QToolBar *toolBar;
	QToolBar *clipToolBar;
	QProgressBar *progressBar;
	QLabel *coordLonLat;
	QLabel *coordXY;
	QLabel *statusText;
	QStatusBar *statusBar;
// ================================================================================================
//                                              QT 
// ================================================================================================
#pragma endregion
};


}}}}

#endif
